package com.guo.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.guo.common.pojo.EasyUITreeNode;
import com.guo.mapper.TbItemCatMapper;
import com.guo.pojo.TbItemCat;
import com.guo.pojo.TbItemCatExample;
import com.guo.pojo.TbItemCatExample.Criteria;
import com.guo.service.ItemCatService;
/**
 * 商品分类Service
 * <p>Title: ItemCatServiceImpl</p>
 * <p>Description: </p>
 * @author	guo
 * @date	22 Sep 201721:05:01
 * @version 1.0
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {
	
	@Autowired
	private TbItemCatMapper  itemCatMapper;
	@Override
	public List<EasyUITreeNode> getItemCatList(long parentId) {
		//根据patentId查询子节点列表
		TbItemCatExample example = new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		//设置查询条件
		criteria.andParentIdEqualTo(parentId);
		//执行查询
		List<TbItemCat> list = itemCatMapper.selectByExample(example);
		//创建返回结果list
		List<EasyUITreeNode> resultList = new ArrayList<>();
		//把列表转换成EasyUiTreeNode列表
		for (TbItemCat tbItemCat : list) {
			EasyUITreeNode node = new EasyUITreeNode();
			//设置属性
			node.setId(tbItemCat.getId());
			node.setText(tbItemCat.getName());
			node.setState(tbItemCat.getIsParent()?"closed":"open");
			//添加结果集列表
			resultList.add(node);
		}
		//返回结果
		return resultList;
	}

	

}
